package com.cloud.core.graphx

import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.graphx.GraphLoader

import java.util.Calendar

object PageRank_01 {

  def main(args: Array[String]): Unit = {
    val sparkConf = new SparkConf()
      .setMaster("local")
      .setAppName("PageRank_01")

    val sparkContext = new SparkContext(sparkConf)
    // 导入边
    val graph = GraphLoader.edgeListFile(sparkContext,
      "data/com-youtube.ungraph.txt")


    val vertexCount = graph.numVertices

    val vertices = graph.vertices

    vertices.count()

    val edgeCount = graph.numEdges

    val edges = graph.edges
    edges.count()

    val staticPageRank = graph.staticPageRank(10)
    staticPageRank.vertices.collect()

    Calendar.getInstance().getTime
    val pageRank = graph.pageRank(0.001).vertices
    Calendar.getInstance().getTime

    println(pageRank.top(5).mkString("\n"))

  }
}
